<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>问题分类</el-breadcrumb-item>
    </el-breadcrumb>



    <!--列表-->
    <el-table size="small"
              :data="categoryList"
              highlight-current-row
              v-loading="loading"
              border
              element-loading-text="拼命加载中"
              style="width: 100%;">
      <el-table-column align="center"
                       type="selection"
                       width="60">
      </el-table-column>
      <el-table-column sortable
                       prop="categoryNumber"
                       label="分类编号"
                       width="200">
      </el-table-column>
      <el-table-column sortable
                       prop="primaryCategory"
                       label="一级分类"
                       width="100">
      </el-table-column>
      <el-table-column sortable
                       prop="secondaryName"
                       label="问题类型"
                       width="100">
      </el-table-column>
         <el-table-column align="center" sortable prop="status" label="是否显示" min-width="50">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.status=='1'" active-color="#13ce66" inactive-color="#ff4949" @change="editStatus(scope.$index,scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column sortable
                       prop="workOrderNum"
                       label="工单数量"
                       width="100">
      </el-table-column>
      <el-table-column align="center"
                       label="操作"
                       min-width="100">
        <template slot-scope="scope">
          <el-button size="mini"
                     type="primary"
                     @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini"
                     type="danger"
                     @click="deteleCategory(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm"
                @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title"
               :visible.sync="editFormVisible"
               width="30%"
               @click="closeDialog">
      <el-form label-width="120px"
               :model="editForm"
               :rules="rules"
               ref="editForm">
        <el-form-item label="问题类型名"
                      prop="categoryName">
          <el-input size="small"
                    v-model="editForm.categoryName"
                    auto-complete="off"
                    placeholder="请输入问题类型名"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer"
           class="dialog-footer">
        <el-button size="small"
                   @click="closeDialog">取消</el-button>
        <el-button size="small"
                   type="primary"
                   :loading="loading"
                   class="title"
                   @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deptList, deptSave, deptDelete } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        categoryId:"",
        categoryName:"",
        updateById:"",
        token: localStorage.getItem('logintoken'),
      },
      // rules表单验证
      rules: {
        categoryName: [
          { required: true, message: '请输入分类名字', trigger: 'blur' },
        ],
      },
      formInline: {
        page: 1,
        limit: 10,
        varLable: '',
        varName: '',
        token: localStorage.getItem('logintoken'),
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken'),
      },
      userparm: [], //搜索权限
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
      },
      //搜索条件
      tsWorkOrder:{
          wo_number:"",
          woSubmitId:4,
          woProTypeId:"",
          woSubmitTime:""
      },
      //
      categoryList:[],
      //删除的对象
      deletetsQueCategory:{
         categoryId:"",
         updateById:""
      },
      //修改状态的工单分类对象
      updateQueCategoryStatusVo:{
        updateById:"",
        categoryId:"",
        status:"",
        depId:""
      },
    }
  },
  // 注册组件
  components: {
    Pagination,
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取工单列表
    getdata() {
      this.$axios.get("/api/tsQueCategory/list/"+this.formInline.page+"/"+this.formInline.limit,this.tsWorkOrder).then((res)=>{
        //分页对象
        console.log(res.data.data);
        let page=res.data.data
        this.categoryList=res.data.data.list
        console.log("categoryList",this.categoryList);
        console.log("分页数据为:",page.list);
        this.pageparm.total=page.total
        this.pageparm.currentPage=this.formInline.page
        this.pageparm.pageSize=this.formInline.limit;
      }).catch()
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },

    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      if (row != undefined && row != 'undefined') {
        this.title = '修改'
        this.editForm.categoryName = row.secondaryName
        this.editForm.categoryId=row.categoryId;
        //修改人赋值
        this.editForm.updateById=1
      } else {
        this.title = '添加'
       this.editForm.categoryName = ''
       this.editForm.categoryId = ''
       this.editForm.updateById = ''
      }
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate((valid) => {
        if (valid) {
           this.$axios.put("/api/tsQueCategory/update",this.editForm).then((res)=>{
              this.editFormVisible = false
               this.getdata(this.formInline)
           }).catch()
        } else {
          return false
        }
      })
    },
    //修改分类的状态
    editStatus:function(index,row){
      console.log(row);
         if(row.status=='1'){
          row.status='0';
         }else{
           row.status='1';
         }
        //  this.updateQueCategoryStatusVo.updateById=localStorage.getItem("userId")
        this.updateQueCategoryStatusVo.status=row.status;
        this.updateQueCategoryStatusVo.categoryId=row.categoryId
        this.updateQueCategoryStatusVo.updateById=1
        this.updateQueCategoryStatusVo.depId=row.depId
         //发送请求,更换状态
         this.$axios.put("/api/tsQueCategory/updateStatus",this.updateQueCategoryStatusVo).then((res)=>{
            console.log(res.data);
         })
    },
    // 删除分类
    deteleCategory(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          // //从当前当前行获取分类id
          this.deletetsQueCategory.categoryId=row.categoryId;
          //从当前用户获取id
          this.deletetsQueCategory.updateById=1
          this.$axios.put("/api/tsQueCategory/delete",this.deletetsQueCategory).then((res)=>{
               this.$message("删除成功")
               //从新获取数据
               this.getdata(this.formInline)
          }).catch()
        }).catch()
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    },
  },
}
</script>

<style scoped>
.order-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 